﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace IP2Server
{
    /// <summary>
    /// Class that handles security settings in the server.
    /// </summary>
    class ServerSecurity
    {
        /// <summary>
        /// A method to calculate a MD5 hash given input
        /// Author: Tim Cocu
        /// </summary>
        /// <param name="input">The input-string to hash. (MD5)</param>
        /// <returns>The created MD5 hash</returns>
        public static string CalculateMD5Hash(string strInput)
        {
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] barrInputBytes = System.Text.Encoding.ASCII.GetBytes(strInput);
            byte[] barrHash = md5.ComputeHash(barrInputBytes);

            StringBuilder stringBuilder = new StringBuilder();
            for (int iIndex = 0; iIndex < barrHash.Length; iIndex++)
            {
                stringBuilder.Append(barrHash[iIndex].ToString("X2"));
            }

            //Returns the encrypted stringbuilder as a string
            return stringBuilder.ToString();
        }
    }
}
